package com.yqg.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.manage.entity.Department;
import com.yqg.manage.mapper.DepartmentMapper;
import com.yqg.manage.service.IDepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * DepartmentServiceImpl 服务实现类
 *
 * @author zxf
 * @since 2025-09-16
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {
    @Resource
    private DepartmentMapper departmentMapper;

    @Override
    public Map<String, Object> rootPage(Integer pageNum, Integer pageSize, Long unitId) {
        Map<String,Object> map = new HashMap<>();
        List<Department> departmentList = departmentMapper.rootPage(pageNum,pageSize,unitId);
        Integer count = departmentMapper.rootPageCount(unitId);
        map.put("records",departmentList);
        map.put("total",count);
        return map;
    }

    @Override
    public Map<String, Object> deputyDirectorRootPage(Integer pageNum, Integer pageSize, Long userId, Long unitId) {
        Map<String,Object> map = new HashMap<>();
        List<Department> departmentList = departmentMapper.deputyDirectorRootPage(pageNum,pageSize,userId,unitId);
        Integer count = departmentMapper.deputyDirectorRootPageCount(userId,unitId);
        map.put("records",departmentList);
        map.put("total",count);
        return map;
    }

    @Override
    public Map<String, Object> childDepartment(Long id) {
        Map<String,Object> map =new HashMap<>();
        List<Department> list = departmentMapper.childDepartment(id);
        map.put("records", list);
        map.put("total", list.size());
        return map;
    }
}
